from time import sleep

from selenium import webdriver
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.by import By

url = "https://ke.qq.com/"
driver = webdriver.Chrome()
driver.maximize_window()

wait = WebDriverWait(driver,30)
driver.get(url=url)
sleep(3)

#点击登录
ele_login = (By.XPATH,'//a[contains(@report-attr,"module=login&position=card")]')
wait.until(EC.element_to_be_clickable(ele_login))
login_button =driver.find_element(*ele_login)
login_button.click()

#微信登录
ele_wx = (By.XPATH,'//i[@class="icon-font i-weixin"]')
wait.until(EC.element_to_be_clickable(ele_wx))
wx_button = driver.find_element(*ele_wx)
wx_button.click()

sleep(10)

#手动扫码登录

#打开课程页
sleep(20)
ele_course = (By.XPATH,'//a[@class="mod-entry-user-schedule"]')
wait.until(EC.element_to_be_clickable(ele_course))
course_button = driver.find_element(*ele_course)
course_button.click()

#点击指定课程
ele_target = (By.XPATH,'//p[@title="软件测试之python全栈自动化测试工程师第40期【柠檬班VIP】"]')
wait.until(EC.element_to_be_clickable(ele_target))
target_button = driver.find_element(*ele_target)
target_button.click()

#获取课程title
ele_courses = (By.XPATH,'//div[@class="details-ctn-wrapper"]//div[@class="section-title"]')
wait.until(EC.visibility_of_element_located(ele_courses))
courses = driver.find_elements(*ele_courses)

with open(file=r"F:\course.txt",mode="w",encoding="utf-8") as f:
    for i in courses:
      t=i.text
      f.write(t+'\n')

driver.quit()